package com.oyc.demo.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.oyc.demo.domain.Exporterror;
import com.oyc.demo.mapper.ExporterrorMapper;
import com.oyc.demo.service.ExporterrorService;

/**
 * (Exporterror)表服务实现类
 *
 * @author 杜学森
 * @since 2021-01-21 16:47:13
 */
@Service
public class ExporterrorServiceImpl implements ExporterrorService {
    @Resource
    private ExporterrorMapper exporterrorMapper;

	@Override
	public List<Exporterror> queryAll(Exporterror exporterror) {
		// TODO Auto-generated method stub
		return exporterrorMapper.queryAll(exporterror);
	}

	@Override
	public void insertBatch(List<Exporterror> errList) {
		// TODO Auto-generated method stub
		exporterrorMapper.insertBatch(errList);
	}


	@Override
	@Transactional
	public JSONObject calculate() {
		
		JSONObject obj=new JSONObject();
		
		// 数据二次分流
		exporterrorMapper.inserterror();
		// 根据错误数据删除导入数据
		exporterrorMapper.deleteTemimportExporterror();
		// 删除标准数据
		exporterrorMapper.deleteCablebasicByExporterror();
		// 更新标准中的数据
		exporterrorMapper.updateCablebasicByExporterror();
		//导入失败数量
		int errorcount=exporterrorMapper.errorcount();
		//导入成功的数据数量
		int successcount=exporterrorMapper.successcount();
		//导入省公司
		String provincecompanyname=exporterrorMapper.provincecompanyname();
		//清除临时表数据
		exporterrorMapper.deleteTemimport();
		
        obj.put("provincecompanyname", provincecompanyname==null||provincecompanyname.trim().length()==0?"无":provincecompanyname);
        obj.put("count", errorcount+successcount);
        obj.put("success", successcount);
        obj.put("error", errorcount);
            
		return obj;
	}


	@Override
	@Transactional
	public void clear() {
		exporterrorMapper.deleteTemimport();
		exporterrorMapper.deleteExporterror();
	}

   
}